package com.ptu.spzx.domain.Class.vo;

import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 业务解释层
 * ***无法解释status
 */
@Data
public class ClassesQueryResultVO {
    /**
     * 编号
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 班级名
     */
    private String name;

    private Integer status;

    private String icon;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    /**
     * 数据库临时生成的课程id数组，例如[0,1,2]
     * 由于直接查询会导致分页错误，只能这样
     */
    @JsonIgnore
    private String courseIdsJsonString;

    private List<Long> courseIds;

    public void convertCourseIds() {
        JSONArray objects = new JSONArray(courseIdsJsonString);
        courseIds = objects.toList(Long.class);
    }

}
